package com.cw.jeeyt.dao.impl.system;

import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

import com.cw.jeeyt.dao.intf.system.SysScaffoldConfigDao;
import com.cw.jeeyt.dao.mapper.system.SysScaffoldConfigMapper;
import com.cw.jeeyt.dao.model.system.SysScaffoldConfigDo;
import com.cw.jeeyt.dao.model.system.SysScaffoldConfigExample;
import com.cw.jeeyt.dao.model.system.SysScaffoldConfigKeyDo;
import com.cw.jeeyt.dao.query.system.SysScaffoldConfigQuery;
import com.cw.lang.common.dao.AbstractBaseDaoImpl;
import com.cw.lang.common.pagehelper.PageHelper;
import com.cw.lang.mybatis.dto.PageInfo;
import com.cw.lang.mybatis.dto.PageParam;
import com.cw.lang.common.utils.StringUtil;

/**
 * 系统脚手架配置数据库操作接口实现
 *
 * @author admin
 * @date 2020-05-24 21:04:55
 */
@Repository
public class SysScaffoldConfigDaoImpl extends AbstractBaseDaoImpl<SysScaffoldConfigDo, SysScaffoldConfigMapper>
    implements SysScaffoldConfigDao {
    /**
     * 分页查询
     *
     * @param sysScaffoldConfig 条件
     * @param pageParam 分页参数
     * @return
     */
    @Override
    public PageInfo<SysScaffoldConfigDo> selectPage(SysScaffoldConfigQuery sysScaffoldConfig, PageParam pageParam) {
        SysScaffoldConfigExample example = buildExample(sysScaffoldConfig);
        return PageHelper.<SysScaffoldConfigDo>startPage(pageParam.getPageNum(),
            pageParam.getPageSize()).doSelectPageInfo(() -> getMapper().selectByExample(example));
    }

    /**
     * 根据key查询系统脚手架配置
     *
     * @param id
     * @return
     */
    @Override
    public SysScaffoldConfigDo selectByKey(Long id) {
        SysScaffoldConfigKeyDo sysScaffoldConfigKeyDo = new SysScaffoldConfigKeyDo();
        sysScaffoldConfigKeyDo.setId(id);
        return getMapper().selectByPrimaryKey(sysScaffoldConfigKeyDo);
    }

    /**
     * 根据key删除系统脚手架配置
     *
     * @param id
     * @return
     */
    @Override
    public int deleteByKey(Long id) {
        SysScaffoldConfigKeyDo sysScaffoldConfigKeyDo = new SysScaffoldConfigKeyDo();
        sysScaffoldConfigKeyDo.setId(id);
        return getMapper().deleteByPrimaryKey(sysScaffoldConfigKeyDo);
    }

    /**
     * 查询系统脚手架配置信息
     *
     * @param sysScaffoldConfig 条件
     * @return List<SysScaffoldConfigDo>
     */
    @Override
    public List<SysScaffoldConfigDo> selectByExample(SysScaffoldConfigQuery sysScaffoldConfig) {
        return getMapper().selectByExample(buildExample(sysScaffoldConfig));
    }

    /**
     * 新增系统脚手架配置信息
     *
     * @param sysScaffoldConfig 条件
     * @return int>
     */
    @Override
    public int insertBySelective(SysScaffoldConfigDo sysScaffoldConfig) {
        if (sysScaffoldConfig == null) {
            return -1;
        }
        sysScaffoldConfig.setCreateTime(new Date());
        sysScaffoldConfig.setUpdateTime(new Date());
        return getMapper().insertSelective(sysScaffoldConfig);
    }

    /**
     * 修改系统脚手架配置信息
     *
     * @param sysScaffoldConfig
     * @return
     */
    @Override
    public int updateBySelective(SysScaffoldConfigDo sysScaffoldConfig) {
        if (sysScaffoldConfig == null) {
            return -1;
        }
        sysScaffoldConfig.setUpdateTime(new Date());
        return getMapper().updateByPrimaryKeySelective(sysScaffoldConfig);
    }

    /**
     * 构建系统脚手架配置Example信息
     *
     * @param sysScaffoldConfig
     * @return
     */
    public SysScaffoldConfigExample buildExample(SysScaffoldConfigQuery sysScaffoldConfig) {
        SysScaffoldConfigExample example = new SysScaffoldConfigExample();
        SysScaffoldConfigExample.Criteria criteria = example.createCriteria();
        if (sysScaffoldConfig != null) {
            //添加查询条件
            if (null != sysScaffoldConfig.getId()) {
                criteria.andIdEqualTo(sysScaffoldConfig.getId());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getScaffoldCode())) {
                criteria.andScaffoldCodeEqualTo(sysScaffoldConfig.getScaffoldCode());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getScaffoldName())) {
                criteria.andScaffoldNameEqualTo(sysScaffoldConfig.getScaffoldName());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getPomGroupId())) {
                criteria.andPomGroupIdEqualTo(sysScaffoldConfig.getPomGroupId());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getPomArtifactId())) {
                criteria.andPomArtifactIdEqualTo(sysScaffoldConfig.getPomArtifactId());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getPomName())) {
                criteria.andPomNameEqualTo(sysScaffoldConfig.getPomName());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getPomVersion())) {
                criteria.andPomVersionEqualTo(sysScaffoldConfig.getPomVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getBasePackage())) {
                criteria.andBasePackageEqualTo(sysScaffoldConfig.getBasePackage());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getJavaVersion())) {
                criteria.andJavaVersionEqualTo(sysScaffoldConfig.getJavaVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getSpringbootVersion())) {
                criteria.andSpringbootVersionEqualTo(sysScaffoldConfig.getSpringbootVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getImplodedSpringcloud())) {
                criteria.andImplodedSpringcloudEqualTo(sysScaffoldConfig.getImplodedSpringcloud());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getSpringcloudVersion())) {
                criteria.andSpringcloudVersionEqualTo(sysScaffoldConfig.getSpringcloudVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getImplodedAlibabaDubbo())) {
                criteria.andImplodedAlibabaDubboEqualTo(sysScaffoldConfig.getImplodedAlibabaDubbo());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getAlibabaDubboVersion())) {
                criteria.andAlibabaDubboVersionEqualTo(sysScaffoldConfig.getAlibabaDubboVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getRegistryCenterType())) {
                criteria.andRegistryCenterTypeEqualTo(sysScaffoldConfig.getRegistryCenterType());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getRegistryVersion())) {
                criteria.andRegistryVersionEqualTo(sysScaffoldConfig.getRegistryVersion());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getDaoHandleType())) {
                criteria.andDaoHandleTypeEqualTo(sysScaffoldConfig.getDaoHandleType());
            }
            if (StringUtil.isNotEmpty(sysScaffoldConfig.getDaoHandleVersion())) {
                criteria.andDaoHandleVersionEqualTo(sysScaffoldConfig.getDaoHandleVersion());
            }
            if (null != sysScaffoldConfig.getCreateBy()) {
                criteria.andCreateByEqualTo(sysScaffoldConfig.getCreateBy());
            }
            if (null != sysScaffoldConfig.getCreateTimeBegin()) {
                criteria.andCreateTimeGreaterThanOrEqualTo(sysScaffoldConfig.getCreateTimeBegin());
            }
            if (null != sysScaffoldConfig.getCreateTimeEnd()) {
                criteria.andCreateTimeLessThanOrEqualTo(sysScaffoldConfig.getCreateTimeEnd());
            }
            if (null != sysScaffoldConfig.getUpdateBy()) {
                criteria.andUpdateByEqualTo(sysScaffoldConfig.getUpdateBy());
            }
            if (null != sysScaffoldConfig.getUpdateTimeBegin()) {
                criteria.andUpdateTimeGreaterThanOrEqualTo(sysScaffoldConfig.getUpdateTimeBegin());
            }
            if (null != sysScaffoldConfig.getUpdateTimeEnd()) {
                criteria.andUpdateTimeLessThanOrEqualTo(sysScaffoldConfig.getUpdateTimeEnd());
            }
        }
        return example;
    }
}
